package com.cysion.study.ui

import android.text.TextUtils
import android.view.View
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.utils.whiteTextTheme
import com.cysion.other.color
import com.cysion.other.startActivity_ex
import com.cysion.targetfun._subscribe
import com.cysion.study.uibox.bar.TopBar
import com.cysion.study.R
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import kotlinx.android.synthetic.main.activity_money.*

class MoneyActivity : BaseActivity(), View.OnClickListener {


    override fun getLayoutId(): Int = R.layout.activity_money

    override fun initView() {
        whiteTextTheme(color(R.color.main_cl))
        topbar.apply {
            setTitle("我的账户")
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.LEFT) {
                    finish()
                }
            }
        }



        rl_qz.setOnClickListener(this)
        rl_tx.setOnClickListener(this)
        rl_card.setOnClickListener(this)
        rl_blance.setOnClickListener(this)


    }

    override fun onResume() {
        super.onResume()
        getUserInfos()
    }
    private fun getUserInfos() {
        ApiClient.api.getUserInfos(UserCache.token).compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    if (!TextUtils.isEmpty(it.id)) {
                        UserCache.save(it)
//                        tv_money.text = "￥ "+UserCache.userInfo?.money.toString()
                        tv_money.text = "￥ "+it.money
                    }
                }
            }
    }


    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.rl_qz->{//充值
                startActivity_ex<RecharActivity>()
            }
            R.id.rl_tx->{//提现
                startActivity_ex<WithDrawActivity>()
            }
            R.id.rl_card->{//银行卡
                startActivity_ex<BandCardActivity>()
            }
            R.id.rl_blance->{//零钱明细
                startActivity_ex<BlanceDetailActivity>()
            }
        }
    }
    override fun closeMvp() {
    }

}
